package memento;


import java.util.ArrayList;
import java.util.HashMap;

public class Caretaker {

    private ArrayList<GameRome> states;
    private HashMap<String, ArrayList<GameRome>> rotesMementos = new HashMap<>();

    public void setRotesMementos(String roteName, GameRome gameRome){

        //找到对应角色的list集合
        states = rotesMementos.get(roteName);
        //确保每组states集合对应一个角色
        if (!rotesMementos.containsKey(roteName)){
            states = new ArrayList<>();
        }

        //把当前状态备份存到相应的list集合中
        states.add(gameRome.getMemento());

        //每个角色对应一组状态
        rotesMementos.put(roteName, states);

    }

    public GameRome getRotesMementos(String roteName, int states) {
        //返回存在在hashMap集合中的对应角色的对应状态
        return rotesMementos.get(roteName).get(states);
    }

}
